<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Project extends Model
{
    protected $table = "project";
    public $timestamps = false;
    public $guarded = [];

    public function businessLicenseImage(): Attribute
    {
        return Attribute::make(
            get: fn ($value) => is_null($value) ? null : json_decode($value,true),
            set: fn ($value) => is_array($value) ? json_encode($value) : $value,
        );
    }

    public function wonerIdcardImage(): Attribute
    {
        return Attribute::make(
            get: fn ($value) => is_null($value) ? null : json_decode($value,true),
            set: fn ($value) => is_array($value) ? json_encode($value) : $value,
        );
    }

    public function wonerCreditImage(): Attribute
    {
        return Attribute::make(
            get: fn ($value) => is_null($value) ? null : json_decode($value,true),
            set: fn ($value) => is_array($value) ? json_encode($value) : $value,
        );
    }

    public function userIdcardImage(): Attribute
    {
        return Attribute::make(
            get: fn ($value) => is_null($value) ? null : json_decode($value,true),
            set: fn ($value) => is_array($value) ? json_encode($value) : $value,
        );
    }

    public function userCreditImage(): Attribute
    {
        return Attribute::make(
            get: fn ($value) => is_null($value) ? null : json_decode($value,true),
            set: fn ($value) => is_array($value) ? json_encode($value) : $value,
        );
    }

    public function otherFileUrl(): Attribute
    {
        return Attribute::make(
            get: fn ($value) => is_null($value) ? null : json_decode($value,true),
            set: fn ($value) => is_array($value) ? json_encode($value) : $value,
        );
    }
}
